<?php
class Alipay {
	private $parameter = array(
		"service" => "create_direct_pay_by_user",
		"payment_type"	=> 1,
		"notify_url"	=> 'http://www.class100.com/aliNotify.htm',
		"return_url"	=> 'http://www.class100.com/user_respond.htm',
		"seller_email"	=>  'ruziniukeji@163.com',
		"show_url"	=> 'http://12525544',
		"anti_phishing_key"	=> '',
		"exter_invoke_ip"	=> '',
	);
	private $alipay_config = array(
		'partner' => '2088312753840324',
		'key' => 'nd5ceralz7bqwxp4yrp9usvj1ytuuk54',
		'sign_type'  =>'MD5',
		'input_charset' =>'utf-8',
		'transport' => 'http'
	);
	
	public function __construct(){
		global $data_key_url;
		$this->alipay_config['cacert'] = $data_key_url.'cacert.pem';
	}
	public function pay($data){
		require("alipay_submit.class.php");
		$this->parameter['out_trade_no'] = $data['id'];
		$this->parameter['subject'] = $data['WIDsubject'];
		$this->parameter['total_fee'] = $data['online_money'];
		$this->parameter['body'] = $data['WIDbody'];
		$this->parameter['partner'] = $this->alipay_config['partner'];
		$this->parameter['_input_charset'] = $this->alipay_config['input_charset'];
		$this->parameter['return_url'] = $this->parameter['return_url'].'?code=alipay&pay_log_id='.$data['pay_log_id'];
		$alipaySubmit = new AlipaySubmit($this->alipay_config);
		$html_text = $alipaySubmit->buildRequestForm($this->parameter,"post", "确认");
		return $html_text;
	}
	
	public function notify($data){
		require("alipay_notify.class.php");
		//计算得出通知验证结果
		$alipayNotify = new AlipayNotify($this->alipay_config);
		$verify_result = $alipayNotify->verifyNotify();
		if($verify_result) {//验证成功
			//商户订单号
			$out_trade_no = $data['out_trade_no'];
			//支付宝交易号
			$trade_no = $data['trade_no'];
			//交易状态
			$trade_status = $data['trade_status'];
			if($data['trade_status'] == 'TRADE_FINISHED') {	
				
			}else if ($_POST['trade_status'] == 'TRADE_SUCCESS') {
				
			}	
				
			return  true;  ///"success";		//请不要修改或删除
		}
		else {
			//若有余额支付，需要反反账户
			return   false; ///"fail";
		}
	}
	
	public function returnUrl($data){
		require("alipay_notify.class.php");
		//计算得出通知验证结果
		$alipayNotify = new AlipayNotify($this->alipay_config);
		$verify_result = $alipayNotify->verifyReturn();
		if($verify_result) {//验证成功
			//商户订单号
			$out_trade_no = $data['out_trade_no'];
			//支付宝交易号$data
			$trade_no = $data['trade_no'];
			//交易状态
			$trade_status = $data['trade_status'];
			if($data['trade_status'] == 'TRADE_FINISHED') {
				
			}else if ($_POST['trade_status'] == 'TRADE_SUCCESS') {
				//更新系统
			}	
			return  true;  /////请不要修改或删除
		}
		else {
			//若有余额支付，需要反反账户
			return   false; ///"fail";
		}
	}
}

?>